package com.cf.log.core.holder;


import com.cf.log.core.LogConstant;
import com.cf.log.core.User;

import java.util.HashMap;
import java.util.Map;

/**
 * game-server-RequestHolder
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/5/16 下午 01:45
 */
public class RequestHolder {

    protected static ThreadLocal<Map> contextThreadLocal = new ThreadLocal<Map>() {
        @Override
        protected Map initialValue() {
            return new HashMap();
        }
    };


    public static void set(String key, Object data) {
        Map map = contextThreadLocal.get();
        map.put(key, data);
    }


    public static User getUser(String key) {
        Map map = contextThreadLocal.get();
        return (User) map.get(LogConstant.userKey);
    }


    public static void clean() {
        contextThreadLocal.remove();
    }


}
